﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Common {
    public class FpsCounter {
        public static event Action<double> FrameMillsecondTick;
        public static event Action<double> FpsTick;
        static double lastTime = InputControls.getTime();
        static int frames=0;
        
        public static double FpsInterval { get; set; } = 1.0;
        public static void  CountFps() {
          
            double currentTime = InputControls.getTime();
            frames++;
            double deltaTime = currentTime - lastTime;
            if (deltaTime > FpsInterval) {
                fireEvents(deltaTime);
                frames = 0;
                lastTime += FpsInterval;
            }

        }

        private static void fireEvents(double deltaTime) {
            if (FrameMillsecondTick != null) {
                double millsecondsPerFrame = 1000 * FpsInterval / frames;
                FrameMillsecondTick(millsecondsPerFrame);
            }
            if (FpsTick != null) {
                FpsTick(frames / deltaTime);
            }
        }

        //private static void fireEvents(double deltaTime, object fps, double fpsInterval) {
        //    if (FrameMillsecondTick != null) {
        //        double millsecondsPerFrame = 1000 * psInterval / frames;
        //        FrameMillsecondTick(
        //    }
        //}

        private static void fireEvents(double deltaTime, object fps) {
  
        }

 
    }
}
